include "map_builder.lua"
include "trajectory_builder.lua"

options = {
  map_builder = MAP_BUILDER,
  trajectory_builder = TRAJECTORY_BUILDER,
  
  -- Add num_point_clouds here
  num_point_clouds = 1,  -- 使用点云数据
  map_frame = "map",
  tracking_frame = "base_link",
  published_frame = "base_link",
  odom_frame = "odom",
  provide_odom_frame = true,
  publish_frame_projected_to_2d = true,

  use_odometry = false,
  use_nav_sat = false,
  use_landmarks = true,  -- 使用反光柱作为 landmarks
  num_laser_scans = 0,   -- 不使用激光扫描数据
  num_multi_echo_laser_scans = 0,
  num_subdivisions_per_laser_scan = 1,

  lookup_transform_timeout_sec = 0.2,
  submap_publish_period_sec = 0.1,  -- 与雷达频率匹配
  pose_publish_period_sec = 0.005,
  trajectory_publish_period_sec = 0.03,

  fixed_frame_pose_sampling_ratio = 1.0,
  rangefinder_sampling_ratio = 1.0,
  odometry_sampling_ratio = 1.0,
  imu_sampling_ratio = 1.0,
  landmarks_sampling_ratio = 1.0,  -- landmarks 采样比例
}

-- Ensure range_data_inserter is configcured correctly
MAP_BUILDER.use_trajectory_builder_2d = true       --注释1
MAP_BUILDER.range_data_inserter = {
  range_data_inserter_type = "PROBABILITY_GRID_INSERTER_2D",
  probability_grid_range_data_inserter = {
    hit_probability = 0.55,
    miss_probability = 0.49,
    insert_free_space = true,
  },
}



TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.num_accumulated_range_data = 1

TRAJECTORY_BUILDER_2D.min_range = 0.15
TRAJECTORY_BUILDER_2D.max_range = 25.0
TRAJECTORY_BUILDER_2D.min_z = -0.8
TRAJECTORY_BUILDER_2D.max_z = 2.0
TRAJECTORY_BUILDER_2D.voxel_filter_size = 0.05

TRAJECTORY_BUILDER_2D.missing_data_ray_length = 30.0       --注释1
TRAJECTORY_BUILDER_2D.adaptive_voxel_filter.max_range = 50.0       --注释1
TRAJECTORY_BUILDER_2D.adaptive_voxel_filter.min_num_points = 100       --注释1
TRAJECTORY_BUILDER_2D.adaptive_voxel_filter.max_length = 0.5       --注释1

TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.1       --注释1
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.angular_search_window = 0.349066       --注释1

TRAJECTORY_BUILDER_2D.ceres_scan_matcher.translation_weight = 10.0       --注释1
TRAJECTORY_BUILDER_2D.ceres_scan_matcher.rotation_weight = 40.0       --注释1
TRAJECTORY_BUILDER_2D.ceres_scan_matcher.ceres_solver_options.max_num_iterations = 20       --注释1

TRAJECTORY_BUILDER_2D.submaps.grid_options_2d.resolution = 0.02  -- 5cm分辨率       --注释1
TRAJECTORY_BUILDER_2D.submaps.num_range_data = 90       --注释1

POSE_GRAPH.optimize_every_n_nodes = 90
POSE_GRAPH.constraint_builder.min_score = 0.55
POSE_GRAPH.global_sampling_ratio = 0.003
POSE_GRAPH.global_constraint_search_after_n_seconds = 10.

return options
